//
//  TuiJianViewCell.m
//  ShopDemo
//
//  Created by Sunshine on 2018/9/4.
//  Copyright © 2018年 飞扬的青春. All rights reserved.
//

#import "TuiJianViewCell.h"
#import "FirstOneCollectionCell.h"
@implementation TuiJianViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        UILabel *leftlabe = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 40*kJLXWidthScale)];
        leftlabe.text = @"为你推荐";
        leftlabe.font = [UIFont systemFontOfSize:18*kJLXWidthScale];
        leftlabe.textColor = [UIColor redColor];
        leftlabe.textAlignment = NSTextAlignmentCenter;
        self.centerlab = leftlabe;
        [self.contentView addSubview:leftlabe];
        [self creatCollectionviewMethod];
    }
    return self;
}



-(void)creatCollectionviewMethod{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    [layout setScrollDirection:UICollectionViewScrollDirectionVertical];
    self.listCollectionview = [[ UICollectionView alloc ] initWithFrame:CGRectMake(0, 50*kJLXWidthScale, kScreenWidth, 150*kJLXWidthScale) collectionViewLayout :layout];
    [self.contentView addSubview:self.listCollectionview];
    if (kScreenHeight == 812) {
        self.listCollectionview.sd_layout
        .bottomSpaceToView(self, 34);
    }
    self.listCollectionview.delegate = self;
    self.listCollectionview.dataSource = self;
    self.listCollectionview.backgroundColor = [UIColor whiteColor];
    [self.listCollectionview registerClass :[ FirstOneCollectionCell class ] forCellWithReuseIdentifier : @"twocell" ];
}


#pragma mark--------------------UICollectionViewDelegateFlowLayout,UICollectionViewDelegate, UICollectionViewDataSource
//cell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.dataArray.count;
}
//
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    FirstOneCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"twocell" forIndexPath:indexPath];
    NSDictionary *dic = self.dataArray[indexPath.row];
    NSURL *url = [NSURL URLWithString:[MethodClass returnUrlSetStrWSDLURL:dic[@"GOODS_PIC"]]];
    [cell.titImageview sd_setImageWithURL:url];
    cell.titlab.text = [NSString stringWithFormat:@"%@",dic[@"GOODS_NAME"]];
    return cell;
    
}
#pragma mark-------------------布局代理
//设置每个cell的宽和高
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(kScreenWidth / 2-2, 200*kJLXWidthScale);
}
//设置分区缩进
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(8*kJLXWidthScale, 0, 8*kJLXWidthScale, 0);
}
//设置每个分区之间最小的行间距和列间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 1;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 1;
}
#pragma mark--------------------------cell点击事件
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
//    self.detailBlock(self.dataArray[indexPath.row]);
    
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
